import request from '@/router/axios';

export const getList = (current, size, params) => {
  return request({
    url: '/api/mes-product/processwo/page',
    method: 'post',
    params: {
      current,
      size
    },
    data: {
      ...params
    }
  });
};

export const getDetail = (id) => {
  return request({
    url: '/api/mes-product/work-order/detail',
    method: 'get',
    params: {
      id
    }
  });
};

export const remove = (ids) => {
  return request({
    url: '/api/mes-product/work-order/remove?ids=' + ids,
    method: 'get'
  });
};

export const add = (row) => {
  return request({
    url: '/api/mes-product/work-order/submit',
    method: 'post',
    data: row
  });
};

export const update = (id, remark) => {
  return request({
    url: '/api/mes-product/processwo/edit',
    method: 'get',
    params: {
      id,
      remark
    }
  });
};

// 派工
export const workDispatch = (row) => {
  return request({
    url: '/api/mes-product/workorder/dispatch',
    method: 'POST',
    data: row
  });
};

// 完工
export const workFinished = (id) => {
  return request({
    url: '/api/mes-product/workorder/finished',
    method: 'POST',
    params: {
      id
    }
  });
};

// 撤回
export const workWithdraw = (id) => {
  return request({
    url: '/api/mes-product/workorder/withdraw',
    method: 'POST',
    params: {
      id
    }
  });
};

// 根据订单号查询上阶产品列表
export const byPartmasterPrePart = (partId) => {
  return request({
    url: '/api/mes-admin/partmaster/list-pre-part-not-current-part',
    method: 'get',
    params: {
      partId
    }
  });
};

// 查询产线list
export const findProductionlineList = (partId) => {
  return request({
    url: '/api/mes-product/productionline/list',
    method: 'get',
    params: {}
  });
};

// 拆分工单
export const workorderSplit = (row) => {
  return request({
    url: '/api/mes-product/work-order/split',
    method: 'POST',
    data: row
  });
};

// 序列号导出
export const exportSN = (row) => {
  return request({
    url: '/api/mes-product/workorder/generation/exportSN',
    method: 'POST',
    data: row
  });
};

// 根据工单号查询产品用料配置
export const getProductMaterialConfig = (workOrderId) => {
  return request({
    url: '/api/mes-product/key/material/config/get-detail',
    method: 'get',
    params: {
      type: 'WORKORDER',
      workOrderId
    }
  });
};

//根据工单号查询工单工艺路线
export const getWorkorderRoute = (workOrderNo) => {
  return request({
    url: '/api/mes-product/process/workorder-route/get-by-wo',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

// 同步用量清单
export const writeBillMaterial = (workOrderId) => {
  return request({
    url: '/api/mes-product/workorder/workOrderNoUsage/find-by-wo',
    method: 'get',
    params: {
      workOrderId
    }
  });
};
// 同步产品用料配置
export const writeWorkOrder = (productPartNo) => {
  return request({
    url: '/api/mes-product/key/material/config/get-detail',
    method: 'get',
    params: {
      type: 'PRODUCT',
      productPartNo
    }
  });
};
// 工单生产数量追加
export const appendWorkOrderQuantity = (row) => {
  return request({
    url: '/api/mes-product/workorder/append/quantity',
    method: 'POST',
    data: row
  });
};

// 追加详情接口
export const getAppendDetail = (workOrderNo) => {
  return request({
    url: '/api/blade-log/operation/work/order/append',
    method: 'get',
    params: {
      workOrderNo
    }
  });
};

// 同步产品工艺
export const productProcessSync = (workOrderId) => {
  return request({
    url: '/api/mes-product/processwo/copy/product/process',
    method: 'POST',
    params: {
      workOrderId
    }
  });
};

// 检验是否有产品工艺路线
export const checkProcessRoute = (productPartId) => {
  return request({
    url: '/api/mes-product/process/submit/check/productPartId',
    method: 'POST',
    params: {
      productPartId
    }
  });
};
